#ifndef FreeTypeFont_H
#define FreeTypeFont_H
#include "TriangleRice.h"
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
#include <freetype/ftoutln.h>
#include <freetype/fttrigon.h>
#include "Singleton.h"
struct xCharTexture
{
	GLuint  m_texID;
	wchar_t m_chaID;
	int     m_Width;
	int     m_Height;
	int     m_adv_x;
	int     m_adv_y;
	int     m_delta_x;
	int     m_delta_y;
public:
	xCharTexture()
	{
		m_texID  = 0;
		m_chaID  = 0;
		m_Width  = 0;
		m_Height = 0;
	}
};

class FreeTypeFont
{
public:
	FreeTypeFont(void);
	~FreeTypeFont(void);


	void load(const char* font_file , int _w , int _h);
	GLuint loadChar(wchar_t ch);
	xCharTexture* getTextChar(wchar_t ch);
	LPWSTR AnsiToUnicode(LPCSTR lpcstr);

	void drawText(wchar_t* _strText,int x , int y, int maxW , int h);
	/// A fairly straight forward function that pushes
	/// a projection matrix that will make object world 
	/// coordinates identical to window coordinates.
	inline void pushScreenCoordinateMatrix() {
		glPushAttrib(GL_TRANSFORM_BIT);
		GLint	viewport[4];
		glGetIntegerv(GL_VIEWPORT, viewport);
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		gluOrtho2D(viewport[0],viewport[2],viewport[3],viewport[1]);
		glPopAttrib();
	};
	/// Pops the projection matrix without changing the current
	/// MatrixMode.
	inline void pop_projection_matrix() {
		glPushAttrib(GL_TRANSFORM_BIT);
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glPopAttrib();
	};
private:
	int   m_w;
	int   m_h;
	FT_Library m_FT2Lib;
	FT_Face    m_FT_Face;
	xCharTexture g_TexID[65536];
};
typedef Singleton<FreeTypeFont> FreeTypeFontSingleton;

#endif


